package com.witframework.core.persistence;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Criterion;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Transactional;

import com.witframework.core.ServiceCallback;

public interface CommonHibernateDao<T> {

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#findById(java.io.Serializable)
	 */
	public abstract Object findById(boolean cache, Class entityClass, Serializable id) throws DataAccessException;

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#findById(java.io.Serializable, boolean)
	 */
	public abstract T findById(boolean cache, Class entityClass, Serializable id, boolean lock);

	public abstract int getAllSize(Class entityClass) throws DataAccessException;

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#getAll()
	 */
	public abstract List<T> getAll(boolean cache, Class entityClass) throws DataAccessException;

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#load(java.io.Serializable)
	 */
	public abstract T load(boolean cache, Class entityClass, Serializable id) throws DataAccessException;

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#save(T)
	 */
	public abstract String save(boolean cache, T entity,ServiceCallback callback) throws DataAccessException;

	public abstract void saveAll(boolean cache, Class entityClass, Collection entityCollection) throws DataAccessException;
	public abstract void saveAll(boolean cache, Class entityClass, Collection entityCollection,ServiceCallback callback) throws DataAccessException;
	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#update(T)
	 */
	public abstract void update(boolean cache, T entity) throws DataAccessException;
	public abstract void update(boolean cache, T entity,ServiceCallback callback) throws DataAccessException;
	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#saveOrUpdate(T)
	 */
	public abstract String saveOrUpdate(boolean cache, T entity);
	public abstract String saveOrUpdate(boolean cache, T entity,ServiceCallback callback);
	public abstract void saveOrUpdateAll(boolean cache, Collection entityCollection);
	public abstract void saveOrUpdateAll(boolean cache, Collection entityCollection,ServiceCallback callback);
	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#delete(java.io.Serializable)
	 */
	public abstract void deleteById(boolean cache, Class entityClass, final Serializable id) throws DataAccessException;
	public abstract void deleteById(boolean cache, Class entityClass, final Serializable id,ServiceCallback callback) throws DataAccessException;
	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#delete(T)
	 */
	public abstract void delete(boolean cache, T entity) throws DataAccessException;
	public abstract void delete(boolean cache, T entity,ServiceCallback callback) throws DataAccessException;
	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#deleteAll(java.util.Collection)
	 */
	public abstract void deleteAll(boolean cache, Collection entities) throws DataAccessException;
	public abstract void deleteAll(boolean cache, Collection entities,ServiceCallback callback) throws DataAccessException;
	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#deleteBy(java.lang.String, java.lang.Object)
	 */
	public abstract void deleteBy(boolean cache, Class entityClass, String propertyName, Object value);
	public abstract void deleteBy(boolean cache, Class entityClass, String propertyName, Object value,ServiceCallback callback);
	public abstract void deleteAllByIds(boolean cache, Class entityClass, String... ids) throws DataAccessException;
	public abstract void deleteAllByIds(boolean cache, Class entityClass,ServiceCallback callback, String... ids) throws DataAccessException;
	public abstract void deleteAll(boolean cache, Class entityClass);
	public abstract void deleteAll(boolean cache, Class entityClass,ServiceCallback callback);
	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#findBy(org.hibernate.Criteria)
	 */
	public abstract List<T> findBy(Criteria crit);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#findByHql(java.lang.String, java.lang.Object)
	 */
	public abstract List findByHql(String hql, Object... values);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#findBy(java.util.Map)
	 */
	public abstract List<T> findBy(boolean cache, Class entityClass, Map<String, Object> filter);

	public abstract List<T> findBy(Class entityClass, Map<String, Object> filter, String orderBy, boolean isAsc);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#findBy(java.lang.String, java.lang.Object)
	 */
	public abstract List<T> findBy(boolean cache, Class entityClass, String propertyName, Object value);

	public abstract T getBy(boolean cache, Class entityClass, String propertyName, Object value);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#findBy(java.lang.String, java.lang.Object, java.lang.String, boolean)
	 */
	public abstract List<T> findBy(boolean cache, Class entityClass, String propertyName, Object value, String orderBy, boolean isAsc);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#createQuery(java.lang.String, java.lang.Object)
	 */
	public abstract Query createQuery(String hql, Object... values);

	public abstract List pagedQuery(String hql, PageSortModel psm, Object... values);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#pagedQuery(java.util.Map, com.westerasoft.wsframework.core.PageSortModel)
	 */
	public abstract List<T> pagedQuery(boolean cache, Class entityClass, Map filter, PageSortModel psm);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#pagedQuery(org.hibernate.Criteria, com.westerasoft.wsframework.core.PageSortModel)
	 */
	public abstract List<T> pagedQuery(Class entityClass, Criteria criteria, PageSortModel psm);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#createCriteria(org.hibernate.criterion.Criterion)
	 */
	public abstract Criteria createCriteria(Class entityClass, Criterion... criterions);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#createCriteria()
	 */
	public abstract Criteria createCriteria(Class entityClass);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#createCriteria(java.util.Map)
	 */
	public abstract Criteria createCriteria(Class entityClass, Map filter);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#createCriteria(java.lang.String, boolean, org.hibernate.criterion.Criterion)
	 */
	public abstract Criteria createCriteria(Class entityClass, String orderBy, boolean isAsc, Criterion... criterions);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#isUnique(T, java.lang.String)
	 */
	public abstract boolean isUnique(T entity, String uniquePropertyNames);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#getId(T)
	 */
	public abstract Serializable getId(T entity) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException;

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#getIdName()
	 */
	public abstract String getIdName(Class entityClass);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#flush()
	 */
	public abstract void flush();

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#clear()
	 */
	public abstract void clear();

	public abstract Criteria createCriteriaForAll(Class entityClass, String propertyValue, Criteria criteria);

	/* (non-Javadoc)
	 * @see com.westerasoft.wsframework.dao.IDao#pagedQueryByFullText(java.lang.Object, com.westerasoft.wsframework.core.PageSortModel)
	 */
	public abstract List pagedQueryByFullText(Class entityClass, String propertyValue, PageSortModel psm, Criteria criteria);

	public abstract T merge(T entity);

	public abstract List<T> pagedQueryByNamedQuery(String queryName, PageSortModel psm) throws DataAccessException;

	public abstract List<T> pagedQueryByNamedQuery(String queryName, Object value, PageSortModel psm) throws DataAccessException;

	public abstract List<T> pagedQueryByNamedQuery(final String queryName, final Object[] values, PageSortModel psm) throws DataAccessException;

	public abstract List<T> pagedQueryByNamedQueryAndNamedParam(String queryName, String paramName, Object value, PageSortModel psm);

	public abstract List<T> pagedQueryByNamedQueryAndNamedParam(String queryName, String[] paramNames, Object[] values, PageSortModel psm);

	public abstract List findByNamedQuery(String queryName) throws DataAccessException;

	public abstract List findByNamedQuery(String queryName, Object value) throws DataAccessException;

	public abstract List findByNamedQuery(String queryName, Object[] values) throws DataAccessException;

	public abstract List findByNamedQueryAndNamedParam(String queryName, String paramName, Object value);

	public abstract List findByNamedQueryAndNamedParam(String queryName, String[] paramNames, Object[] values) throws DataAccessException;

}